package com.lc.pianostudent.activity;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.pianostudent.R;
import com.lc.pianostudent.util.StatusBarCompat;
import com.zcx.helper.activity.AppV4Activity;

/**
 * Created by Administrator on 2016/3/14.
 */
public class BaseActivity extends AppV4Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarCompat.compat(this, getResources().getColor(R.color.textBlack21));
    }

    public void setBackTrue() {

        try {

            findViewById(R.id.rl_title_back).setVisibility(View.VISIBLE);
            findViewById(R.id.rl_title_back).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setHideLeftArrow() {

        try {

            findViewById(R.id.rl_title_back).setVisibility(View.GONE);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setTitleName(String name) {

        try {

            if (name.length() > 10) {

                name = name.substring(0, 10) + "...";

            }

            ((TextView) findViewById(R.id.tv_title_name)).setText(name);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setRightName(String name, int color, View.OnClickListener onClickListener) {

        try {

            findViewById(R.id.rl_title_right).setVisibility(View.VISIBLE);
            ((TextView) findViewById(R.id.tv_title_right)).setText(name);
            ((TextView) findViewById(R.id.tv_title_right)).setTextColor(ContextCompat.getColor(getApplicationContext(), color));
            findViewById(R.id.rl_title_right).setOnClickListener(onClickListener);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setRightImg(String name, int imageSoure, View.OnClickListener onClickListener) {

        try {

            findViewById(R.id.rl_title_right).setVisibility(View.VISIBLE);
            findViewById(R.id.iv_right).setVisibility(View.VISIBLE);
            findViewById(R.id.tv_title_right).setVisibility(View.GONE);

            if (name.length() > 10) {

                name = name.substring(0, 10) + "...";

            }

            ((TextView) findViewById(R.id.tv_title_name)).setText(name);

            ((ImageView) findViewById(R.id.iv_right)).setImageResource(imageSoure);

            findViewById(R.id.rl_title_right).setOnClickListener(onClickListener);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}
